package kelisPkg.loadPackage
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.EventDispatcher;
	import flash.utils.Dictionary;
	
	import starling.textures.Texture;
	import starling.textures.TextureAtlas;

	public class TexturesManager extends EventDispatcher
	{
		
		private  var _textureAtlasDic:Dictionary = new Dictionary();
		static private var _instance:TexturesManager;
		static public function get instance():TexturesManager{
			_instance=_instance||new TexturesManager;
			return _instance;
		}
		public function TexturesManager():void{};
		
		public function addTextureXmlVec(vec:Vector.<String>):void{
			MultiMaterialsManager.instance.addEventListener(LoadEvent.LOAD_COMPLETE,_materialsComplete);
			MultiMaterialsManager.instance.addEventListener(LoadEvent.LOAD_PROGRESS,_loadProgress)
			MultiMaterialsManager.instance.addUrlVec(vec);
		}
		private function _materialsComplete(e:LoadEvent):void
		{
			dispatchEvent(new LoadEvent(LoadEvent.LOAD_COMPLETE));
		}
		private function _loadProgress(e:LoadEvent):void
		{
			dispatchEvent(new LoadEvent(LoadEvent.LOAD_PROGRESS,e.info));
		}
		
		public function addNewMaterial(obj:Object):void{
			var newTextAl:TextureAtlas=new TextureAtlas(obj.texture,obj.xml);
			_textureAtlasDic[obj.url]=newTextAl;
		}
		public  function getAtlas(str:String):TextureAtlas
		{
			
			return _textureAtlasDic[str];
		}
		public  function getTexture(name:String):Texture
		{
			for each(var item:TextureAtlas in _textureAtlasDic){ //遍历  
				if(item.getTexture(name)) {
					return TextureAtlas(item).getTexture(name)
				}
			}  
			return null;
		}
		
	}
}